using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Employee_AdvancedSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // Connection
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Con"].ToString());

        con.Open();

        SqlDataReader dr;

        // choose the approriate command
        String command = "select * from Delivery where status = @status";

        // Prepare command
        SqlCommand cmd = new SqlCommand();

        double temp = 0;
        if (TextBox2.Text != "")
        {
            command += " and Weight >= @wfrom";
            Double.TryParse(TextBox2.Text, out temp);
            cmd.Parameters.AddWithValue("wfrom", temp);
        }
        if (TextBox3.Text != "")
        {
            command += " and Weight <= @wto" ;
            Double.TryParse(TextBox3.Text, out temp);
            cmd.Parameters.AddWithValue("wto", temp);
        }
        if (TextBox4.Text != "")
        {
            command += " and DateOfPosting >= @dfrom";
            cmd.Parameters.AddWithValue("dfrom", TextBox4.Text);
        }
        if (TextBox5.Text != "")
        {
            command += " and DateOfPosting <= @dto";
            cmd.Parameters.AddWithValue("dto", TextBox5.Text);
        }
        cmd.Parameters.AddWithValue("status", CheckBox1.Checked);
        cmd.CommandText = command;
        cmd.Connection = con;

        // Execute query
        dr = cmd.ExecuteReader();

        // Start filling data
        GridView1.DataSource = dr;
        GridView1.DataBind();

        con.Close();
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        //Session["checked"] = CheckBox1.Checked;
    }
}
